//
//  ApplyForClassLeaveViewController.m
//  AttendenceSys
//
//  Created by ld on 16/1/19.
//  Copyright © 2016年 窦芳俊. All rights reserved.
//

#import "ApplyForClassLeaveViewController.h"

@interface ApplyForClassLeaveViewController ()

@end

@implementation ApplyForClassLeaveViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.strNavTitle = @"2016.01.01";
    
    //[self setLeftButtonWithImageName:@"ic_back" bgImageName:@"ic_back"];
    
    [self initData];
    
    [self initView];
    
    // Do any additional setup after loading the view.
}

-(void)initDatePickerView
{
    _datePickerView = [[ASDatePickerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-216-46, [UIScreen mainScreen].bounds.size.width, 216+46)];
    _datePickerView.iTag = 0;
    _datePickerView.editTimeLab.text = @"选择日期";
    _datePickerView.delegate = self;
    [self.view addSubview:_datePickerView];
    
}

-(void)initData
{
    _appClassArr = [[NSMutableArray alloc] init];
    
    ApplyForClassInfo* classInfo = [[ApplyForClassInfo alloc] init];
    classInfo.classTime = @"8:00";
    classInfo.isSelect = NO;
    classInfo.classContent = @"艺术史学与建筑史学习的关系论";
    [_appClassArr addObject:classInfo];
    
    ApplyForClassInfo* classInfo1 = [[ApplyForClassInfo alloc] init];
    classInfo1.classTime = @"9:05";
    classInfo1.isSelect = NO;
    classInfo1.classContent = @"邓小平理论";
    [_appClassArr addObject:classInfo1];
    
    ApplyForClassInfo* classInfo2 = [[ApplyForClassInfo alloc] init];
    classInfo2.classTime = @"10:10";
    classInfo2.isSelect = NO;
    classInfo2.classContent = @"马克思列宁主义原理";
    [_appClassArr addObject:classInfo2];
    
    ApplyForClassInfo* classInfo3 = [[ApplyForClassInfo alloc] init];
    classInfo3.classTime = @"11:05";
    classInfo3.isSelect = NO;
    classInfo3.classContent = @"政治";
    [_appClassArr addObject:classInfo3];
}

-(void)initView
{
    //上下午
    UIButton* morBtn = [[UIButton alloc] initWithFrame:CGRectMake(0,0,[UIScreen mainScreen].bounds.size.width/2,ApplyClassCellHeight)];
 
    [morBtn setTitle:@"上午" forState:UIControlStateNormal];
    [morBtn addTarget:self action:@selector(moraftBtn:) forControlEvents:UIControlEventTouchUpInside];
    morBtn.tag = 100;
    [morBtn setTitleColor:RGB(102, 102, 102) forState:UIControlStateNormal];
    morBtn.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:morBtn];
    
    UIButton* aftBtn = [[UIButton alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2,0,[UIScreen mainScreen].bounds.size.width/2,ApplyClassCellHeight)];
    
    [aftBtn setTitle:@"下午" forState:UIControlStateNormal];
    [aftBtn addTarget:self action:@selector(moraftBtn:) forControlEvents:UIControlEventTouchUpInside];
    aftBtn.tag = 200;
    [aftBtn setTitleColor:RGB(102, 102, 102) forState:UIControlStateNormal];
    aftBtn.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:aftBtn];
    
    
    UIImageView* lineView = [[UIImageView alloc] initWithFrame:CGRectMake(0,ApplyClassCellHeight-1,[UIScreen mainScreen].bounds.size.width,1)];
    [lineView setBackgroundColor:RGB(240, 240, 240)];
    [self.view addSubview:lineView];
    
    _bottomLineView = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/8,ApplyClassCellHeight-1,[UIScreen mainScreen].bounds.size.width/4,1)];
    [_bottomLineView setBackgroundColor:RGB(252, 120, 61)];
    [self.view addSubview:_bottomLineView];
    
//    UIImageView* linerightView = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width*5/8,ApplyClassCellHeight-1,[UIScreen mainScreen].bounds.size.width/4,1)];
//    linerightView.hidden = YES;
//    [linerightView setBackgroundColor:RGB(252, 120, 61)];
//    [self.view addSubview:linerightView];
    
    //init tableView
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.frame = CGRectMake(0, ApplyClassCellHeight, self.view.frame.size.width, self.view.frame.size.height);
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.scrollEnabled = NO;
    [_tableView registerClass:[ApplyClassTableViewCell class] forCellReuseIdentifier:NSStringFromClass([ApplyClassTableViewCell class])];
    [self.view addSubview:_tableView];
    
    //next
    
    UIButton* nextBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    nextBtn.frame = CGRectMake(50,ApplyClassCellHeight*(_appClassArr.count+1) + 120,[UIScreen mainScreen].bounds.size.width-50*2,ApplyClassCellHeight+6.5);
    [nextBtn setTitle:@"下一步" forState:UIControlStateNormal];
    nextBtn.layer.cornerRadius = 4.5;
    [nextBtn addTarget:self action:@selector(nextBtn) forControlEvents:UIControlEventTouchUpInside];
   
    [nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    nextBtn.backgroundColor = RGB(252, 120, 61);
    [self.view addSubview:nextBtn];
}

//上下午点击事件响应
-(void)moraftBtn:(id)sender
{
    UIButton* btn = (UIButton*)sender;
    if (100 == btn.tag) {
        _bottomLineView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/8,ApplyClassCellHeight-1,[UIScreen mainScreen].bounds.size.width/4,1);
    }
    if (200 == btn.tag) {
        _bottomLineView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width*5/8,ApplyClassCellHeight-1,[UIScreen mainScreen].bounds.size.width/4,1);
    }
}

//下一步点击事件响应
-(void)nextBtn
{
//    UIView* sourceView = [self topView];
//    _backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0 ,sourceView.frame.size.width, sourceView.frame.size.height - 216 - 46)];
//    [_backgroundView setBackgroundColor:[UIColor blackColor]];
//    _backgroundView.alpha = 0.5;
//    [sourceView addSubview:_backgroundView];
//    [self initDatePickerView];
    
    
    AppForClaLeaUpLoadPhoViewController* appForClassViewCtrl = [[AppForClaLeaUpLoadPhoViewController alloc] init];
    appForClassViewCtrl.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:appForClassViewCtrl animated:YES];
}

-(UIView*)topView {
    UIViewController *recentView = self;
    
    while (recentView.parentViewController != nil) {
        recentView = recentView.parentViewController;
    }
    return recentView.view;
}

//删除北京视图
-(void)removeBackView
{
    if (_backgroundView) {
        [_backgroundView removeFromSuperview];
        _backgroundView = nil;
    }
}

//ASDatePickerViewDelegate
-(void)datePickerCancel
{
    [self removeBackView];
}

-(void)dataPickSelect:(NSInteger)selectTag selectDate:(NSString*)selectData
{
    [self removeBackView];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_appClassArr count];
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ApplyClassTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ApplyClassTableViewCell class])];
    
    ApplyForClassInfo* cancleInfo = [_appClassArr objectAtIndex:indexPath.row];
    cell.classRowLab.text = [NSString stringWithFormat:@"%ld",indexPath.row+1];
    cell.classTimeLab.text = [NSString stringWithFormat:@"%@",cancleInfo.classTime];
    cell.classContentLab.text = [NSString stringWithFormat:@"%@",cancleInfo.classContent];
    cell.claSeleImage.hidden = !cancleInfo.isSelect;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return ApplyClassCellHeight;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    ApplyForClassInfo* cancleInfo = [_appClassArr objectAtIndex:indexPath.row];
    cancleInfo.isSelect = !cancleInfo.isSelect;
    
    [_tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
